package ioperation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要借阅的书名");
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getBook(i);
            if(name.equals(book.getName())){
                if(book.isBorrowed()){
                    System.out.println(name+"已经被借走");
                    return;
                }
                System.out.println("借阅成功 "+name);
                book.setBorrowed(true);//****
                return;
            }
        }
        System.out.println("没有"+name+"这本书");
    }
}
